﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;
using Common.EventHandler;
using Microsoft.Xna.Framework;

namespace UIComponentSprite.Building.Menu
{
    /// <summary>
    /// 建筑菜单控制
    /// </summary>
    public class MenuController:UserControlledSprite
    {
        public MenuSprite MenuSprite1 = new MenuSprite(new string[] { "内 政", "军 政", "外 交", "人 事" });
        public MenuSprite MenuSprite11 = new MenuSprite(new string[] { "农 业", "商 业", "筑 城", "技 术", "文 化", "治 安", "民 心" });
        public MenuSprite MenuSprite12 = new MenuSprite(new string[] { "出 征", "训 练", "新 编", "解 散" });
        public MenuSprite MenuSprite14 = new MenuSprite(new string[] { "登 庸","任 命","褒 奖"});

        public MenuController()
        {
            foreach (var item in MenuSprite1.Items)
            {
                switch (item.Text)
                {
                    case "内 政":
                        item.ChildMenuSprite = MenuSprite11;
                        MenuSprite11.ParentItemSprite = item;
                        break;
                    case "军 政":
                        item.ChildMenuSprite = MenuSprite12;
                         MenuSprite12.ParentItemSprite = item;
                        break;
                    case "人 事":
                        item.ChildMenuSprite = MenuSprite14;
                        MenuSprite14.ParentItemSprite = item;
                        break;
                }
                if (item.ChildMenuSprite != null)
                {
                    item.MoveOnEvent += new MoveOnEventHandler(item.ChildMenuSprite.MoveOnEventHandlerByParentItem);
                }
              
            }
        }
        public override void Draw(GameTime gameTime)
        {
            if (!Showing)
                return;
           this.MenuSprite1.Draw(gameTime);
           this.MenuSprite11.Draw(gameTime);
           this.MenuSprite12.Draw(gameTime);
           this.MenuSprite14.Draw(gameTime);
        }

        public override void Update(GameTime gameTime)
        {
            if (!Showing)
                return;
            this.MenuSprite1.Update(gameTime);
            this.MenuSprite11.Update(gameTime);
            this.MenuSprite12.Update(gameTime);
            this.MenuSprite14.Update(gameTime);
        }

        /// <summary>
        /// 控制精灵不显示，鼠标在精灵显示区域内则不关闭
        /// </summary>
        public override void UnShowByAre(object args)
        {
            this.MenuSprite1.UnShowByAre(null);
            this.MenuSprite11.UnShowByAre(null);
            this.MenuSprite12.UnShowByAre(null);
            this.MenuSprite14.UnShowByAre(null);
        }
    }
}
